import { netWork } from '@/network/request.js';

class Axios { // Axios请求构造类
  constructor () {
  }

  getRequst (url, params = null) { // GET请求函数
    return netWork({
      url,
      method: 'GET',
      params
    })
  }
  
  getPost (url, data = null) { // POST请求函数
    return netWork({
      url,
      method: 'POST',
      data
    })
  }

  getPut (url, params = null, data = null) { // POST请求函数
    // console.log(url, params);
    return netWork({
      url,
      method: 'PUT',
      params,
      data
    })
  }

  getDel (url) {
    return netWork({
      url,
      method: 'DELETE'
    })
  }

}



function getGoodsSortData (dataInfoObj) { // 商品分类数据列表
  return new Axios().getRequst('categories', dataInfoObj);
} 

function getAllSortData () { // 获取所有父级分类列表
  return new Axios().getRequst('categories', {
    type: 2
  });
}

function postAddGoodSort (addObj) { // 添加分类
  return new Axios().getPost('categories', addObj);
}

function getFindItemById (id) { // 通过id查询对应项
  return new Axios().getRequst(`categories/${id}`);
}

function putEditorInfo(id, postObj) {
  return new Axios().getPut(`categories/${id}`, null, postObj);
}

function delGoodSortById (id) {
  return new Axios().getDel(`categories/${id}`);
}

export {
  getGoodsSortData,
  getAllSortData,
  postAddGoodSort,
  getFindItemById,
  putEditorInfo,
  delGoodSortById
}


